package the.workshop.bu.dto;

import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.wisteria.framework.util.excel.Excel;
import the.workshop.bu.dto.req.CustomerTelAddReq;
import the.workshop.bu.entity.Customer;
import the.workshop.bu.entity.CustomerTel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class CustomerImportExcel {

    @Excel(title = "公司")
    private String name;

    @Excel(title = "法人")
    private String legal;

    @Excel(title = "股东")
    private String stockholder;

    @Excel(title = "联系电话")
    private String telNumber;

    @Excel(title = "行业")
    private String industry;

    @Excel(title = "区域")
    private String area;

    @Excel(title = "注册资金")
    private String registerFund;

    @Excel(title = "成立日期")
    private Date registerDate;

    @Excel(title = "备注")
    private String remark;

    private String timeTag;

    private List<CustomerTelAddReq> tels = new ArrayList<>();

    public Customer toCustomer() {
        Customer customer = new Customer();
        BeanUtils.copyProperties(this, customer);
        customer.setCreatedTime(new Date());
        customer.setModifiedTime(new Date());
        customer.setStatus("01000");
        customer.setTimeTag(this.timeTag);
        return customer;
    }

    public List<CustomerTel> toCustomerTels(Integer customerId) {
        if (CollectionUtils.isEmpty(tels)) {
            return null;
        }

        List<CustomerTel> records = new ArrayList<>();
        CustomerTel record = null;
        for (CustomerTelAddReq tel : tels) {
            record = new CustomerTel();
            record.setCustomerId(customerId);
            record.setTelNumber(tel.getTelNumber());
            record.setIsLegal(tel.getIsLegal());
            record.setCreatedTime(new Date());
            record.setModifiedTime(new Date());
            records.add(record);
        }
        return records;
    }
}
